//
//  FxBaseViewController.swift
//  Uber
//
//  Created by chen on 16/3/10.
//  Copyright © 2016年 chen. All rights reserved.
//

import UIKit

class FxBaseViewController: UIViewController {
    var activity:FxActivity?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //显示加载过程
    func showActivityInView(view: UIView) -> FxActivity{
        let activity = FxActivityIndicator(view: view)
        activity.frame = view.bounds
        view.addSubview(activity)
        activity.labelText = ""
        return activity
    }
    func hideIndicator(){
        activity?.hide(true)
    }
    func showIndicator(tipMessage:String?,autoHide:Bool,afterDelay:Bool){
        if activity == nil{
            activity = showActivityInView(self.view)
        }
        if tipMessage != nil{
            activity?.labelText = tipMessage
            activity?.show(false)
        }
        if autoHide && activity?.alpha >= 1.0{
            if afterDelay{
                activity?.hide(true, afterDelay: 1.0)
            }else{
                activity?.hide(true)
            }
        }
    }
    func setNavigationItem(title:String,selector:Selector,isRight:Bool){
        var item:UIBarButtonItem!
        if title.hasSuffix("png"){
            item = UIBarButtonItem(image: UIImage(named: title), style: .Plain, target: self, action: selector)
        }else{
            item = UIBarButtonItem(title: title, style: .Plain, target: self, action: selector)
        }
        item.tintColor = UIColor.darkGrayColor()
        if isRight{
            self.navigationItem.rightBarButtonItem = item
        }else{
            self.navigationItem.leftBarButtonItem = item
        }
    }
    
    func goBack(){
       self.dismissViewControllerAnimated(true, completion: nil)
    }
    
    func goRight(){
        
    }
    

}
